﻿#region File Description
/*-----------------------------------------------------------------------------
 Author: Jose Antonio Gallego
 Date: 24/10/2011
 
 License: Ms-PL
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.

 The example companies, organizations, products, domain names,
 e-mail addresses, logos, people, places, and events depicted
 herein are fictitious.  No association with any real company,
 organization, product, domain name, email address, logo, person,
 places, or events is intended or should be inferred.
-----------------------------------------------------------------------------*/
#endregion

using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using Zombsquare.Models;

namespace Zombsquare
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            Agents.ZbrexAgent.AgregarTarea();
        }

        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.DataLoaded)
            {
                App.ViewModel.LoadData();
            }

            DataContext = App.ViewModel;
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ListaScanner.SelectedIndex > -1)
            {
                App.ViewModel.NavigateTo = (ListaScanner.SelectedItem as PushpinModel);

                NavigationService.Navigate(new Uri("/Pages/MapPage/MapPage.xaml", UriKind.Relative));
            }
            ListaScanner.SelectedIndex = -1;
        }

        private void MenuTrivial_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/Trivial/TrivialPage.xaml", UriKind.Relative));
        }

        private void MenuGuia_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/Guia/GuiaPage.xaml", UriKind.Relative));
        }

        private void MenuMapa_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/MapPage/MapPage.xaml", UriKind.Relative));
        }

        private void AR_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/AR/ARPage.xaml", UriKind.Relative));
        }

        private void Bestiario_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/Bestiario/BestiarioPage.xaml", UriKind.Relative));
        }

        private void rectangle2_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {            

            // Lanzar BingMapsTask para buscar una farmacia
            BingMapsTask bingMapsTask = new BingMapsTask();

            //Especificar ubicación actual
            bingMapsTask.Center = App.ViewModel.CurrentLocation;

            //Especificar nivel de zoom
            bingMapsTask.ZoomLevel = 12;

            // Especificar termino de búsqueda          
            bingMapsTask.SearchTerm = "Plaza Mayor, Valladolid, España";
            bingMapsTask.Show();       
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(); 
            if (tile != null) 
            {             
                StandardTileData NewTileData = new StandardTileData 
                {   BackgroundImage = new Uri("/Images/farmaciasTile.png", UriKind.Relative), 
                    Title = "Zombrex", 
                    Count = App.ViewModel.DosisZbrex, 
                    BackContent = "Recuerda no quedarte sin dosis", 
                    BackBackgroundImage = new Uri("farmacias.jpg", UriKind.Relative) 
                }; 
                ShellTile.Create(new Uri("/Pages/Zombrex/ConfigurationPage.xaml", UriKind.Relative), NewTileData);
            }
        }

        private void rectangle5_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            MessageBox.Show("No disponible en esta versión");
        }

        private void rectangle4_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Pages/Zombrex/GuiadeUsoPage.xaml", UriKind.Relative));
        }
    }
}
